package gui;

import processing.core.PApplet;

public class PolyButton extends Button {
	float[] px, py; // coords of the polygon
	boolean drawSecondPoly = false;
	float[] px2, py2; // optional second polygon, for more complex shapes
	boolean drawCutoutPoly = false;
	float[] cx, cy; // option extra polygon in an alternate color
	int cutoutColor;
	boolean showName = true;
		
	public PolyButton(PApplet parentApplet, float[] pos, String name0, 
			          int neutral, int actv, float[] xx, float[] yy) {
		super(parentApplet, pos, name0, neutral, actv);
	    thetextsize = 10;
	    definePoly(xx,yy);
	}   

	void definePoly(float[] xx, float[] yy) {
	    px = xx;
	    py = yy;
	}
	  
	void defineSecondPoly(float[] xx, float[] yy) {
	    drawSecondPoly = true;
	    px2 = xx;
	    py2 = yy;
	}
	  
	void defineCutoutPoly(float[] xx, float[] yy, int col) {
	    drawCutoutPoly = true;
	    cx = xx;
	    cy = yy;
	    cutoutColor = col;
	}
	  
	protected void drawFace() {
	    pa.fill(foreColor());
	    pa.noStroke();
	    pa.beginShape();
	    for (int i=0; i<px.length; i++) {
	    	pa.vertex(x0 + width*px[i], y0 + height*(1 - py[i]));
	    }
	    pa.endShape(pa.CLOSE);
	    if (drawSecondPoly) {
	        pa.beginShape();
	        for (int i=0; i<px2.length; i++) {
	            pa.vertex(x0 + width*px2[i], y0 + height*(1 - py2[i]));
	        }
	        pa.endShape(pa.CLOSE);
	    }
	    if (drawCutoutPoly) {
	        pa.fill(cutoutColor);
	        pa.beginShape();
	        for (int i=0; i<cx.length; i++) {
	            pa.vertex(x0 + width*cx[i], y0 + height*(1 - cy[i]));
	        }
	        pa.endShape(pa.CLOSE);
	    }
	}
	  
	protected void drawName() {
	    if (showName) {
	        pa.textSize(thetextsize);
	        pa.textAlign(pa.CENTER);
	        pa.textLeading(leading*thetextsize);
	        pa.fill(foreColor());
	        pa.text(label, x0 + width/2, y0 + height + (float)1.2*thetextsize);
	    }
	}

}
